package com.whu.helpluojia.controller;

import com.whu.helpluojia.common.BaseContext;
import com.whu.helpluojia.dao.FindDao;
import com.whu.helpluojia.domain.Find;
import com.whu.helpluojia.domain.LostAndFound;
import com.whu.helpluojia.domain.dto.LafDto;
import com.whu.helpluojia.service.FindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/find")
//丢东西
public class FindController {

    @Autowired
    FindService findService;

    @Autowired
    FindDao findDao;

    @PostMapping("/insert")
    public List<LafDto> insert(@RequestBody Find find){
        Long userId= BaseContext.getCurrentId();
        find.setUserId(userId);
        find.setTime(new Date());
        return findService.insert(find);
    }

    @PostMapping("/unmatched")
    public void unmatched(@RequestBody Find find){
        findDao.insert(find);
    }

    @GetMapping("/{id}")
    public Find getFindById(@PathVariable Long id){
        return findService.getById(id);
    }
}
